import { cafReq } from "..";

// export const baseURL =
//   import.meta.env.MODE === "development"
//     ? "/dict"
//     : `${import.meta.env.VITE_REQ_URL}:30009`;

export const baseURL = `${import.meta.env.VITE_FIN_URL}`;
const baseURL2 = `${import.meta.env.VITE_FIN_URL}/finance-config`;
// 查询字典类型列表
export const listType = async (params: any) => {
  return await cafReq(0, { baseURL: baseURL2 }).post(
    "/dict-type/search",
    params
  );
};

// 查询字典类型详细
export const getType = async (dictId: string) => {
  return await cafReq(0, { baseURL: baseURL2 }).get(
    "/dict-type/v1/get/" + dictId
  );
};

// 新增字典类型
export const addType = async (data: any) => {
  return await cafReq(0, { baseURL: baseURL2 }).post("/dict-type/v1/add", data);
};

// 修改字典类型
export const updateType = async (data: any) => {
  return await cafReq(0, { baseURL: baseURL2 }).post(
    "/dict-type/v1/update",
    data
  );
};

// 删除字典类型
export const delType = async (dictId: string) => {
  return await cafReq(0, { baseURL: baseURL2 }).delete(
    "/dict-type/v1/delete/" + dictId
  );
};

// 刷新字典缓存
export const refreshCache = async () => {
  return await cafReq(0, { baseURL: baseURL2 }).get("/dict-type/v1/flushCache");
};

/*********************某个类型字典的具体数据************************/
// 获取字典选择框列表 暂不需要
export const optionselect = async () => {
  return await cafReq(0, { baseURL }).get("/system/dict/type/optionselect");
};
// 查询字典数据列表
export const listData = async (params: any) => {
  return await cafReq(0, { baseURL: baseURL2 }).post(
    "/dict-data/search",
    params
  );
};

// 查询字典数据详细
export const getData = async (dictId: string) => {
  return await cafReq(0, { baseURL: baseURL2 }).get(
    "/dict-data/v1/get/" + dictId
  );
};

// 根据字典类型查询字典数据信息
export const getDicts = async (dictType: string) => {
  return await cafReq(0, { baseURL }).get("/system/dict/data/type/" + dictType);
};

// 新增字典数据
export const addData = async (data: any) => {
  return await cafReq(0, { baseURL: baseURL2 }).post("/dict-data/v1/add", data);
};

// 修改字典数据
export const updateData = async (data: any) => {
  return await cafReq(0, { baseURL: baseURL2 }).post(
    "/dict-data/v1/update",
    data
  );
};

// 删除字典数据
export const delData = async (dictId: string) => {
  return await cafReq(0, { baseURL: baseURL2 }).delete(
    "/dict-data/v1/delete/" + dictId
  );
};
